#include "lvd.h"

/**
  * @brief  Initializes the LVD peripheral according to the specified 
  *         parameters in the LVD_InitStruct.
  * @param  Lvd:  the LVD peripheral.
  * @param  LVD_InitStruct: pointer to a LVD_InitTypeDef structure that contains
  *         the configuration information for the specified LVD peripheral.
  * @retval None
  */
void LVD_Init(LVD_InitTypeDef* LVD_InitStruct)
{

	LVD->CR &= ~LVD_LEVEL_MASK;
	LVD->CR |= LVD_InitStruct->LVD_LEVEL&LVD_LEVEL_MASK;
	
	LVD->CR &= ~LVD_EN_MASK;
	LVD->CR |= LVD_InitStruct->LVD_CMD&LVD_EN_MASK;
	
}

/**
  * @brief  Set trg val         
  * @param  LevelVal: LVD check LEVEL val
  *         
  * @retval None
  */
void LVD_LevelSet(uint8_t LevelVal)
{
	LVD->CR &= ~LVD_LEVEL_MASK;
	LVD->CR |= LevelVal&LVD_LEVEL_MASK;
}


uint8_t LVD_LevelGet(void)
{	
	return LVD->CR&LVD_LEVEL_MASK;
}


/**
  * @brief  Get LVDF Flag         
  * @param  None
  *         
  * @retval LVDF SET or RESET.  
  */
uint8_t LVD_GetFlagStatus(void)
{
	return (LVD->CR&LVD_LVDF_MASK)>>6;
	
}
/**
  * @brief  Clean LVDF Flag         
  * @param  None
  *         
  * @retval None  
  */
void LVD_CleanFlag(void)
{
	LVD->CR |= LVD_LVDF_MASK;
}
/**
  * @brief  Enables or disables Low Power Voltage Detector(LVD).
  * @param  NewState: new state of the LVD.
  *         This parameter can be: ENABLE or DISABLE.
  * @retval None  
  */
void LVD_Cmd(FunctionalState NewState)
{
	if(NewState != DISABLE)
	{
		LVD->CR &= ~LVD_EN_MASK;
		LVD->CR |= LVD_EN_MASK;
	}
	else
	{
		LVD->CR &= ~LVD_EN_MASK;
	}
}
